/********************************************************************************/
/********************************************************************************/

#ifndef TPM2_STRUCTURE_H
#define TPM2_STRUCTURE_H

enum dtype_tpm2_general{
	TYPE(TPM2_INTERNAL)=0x2101,
	TYPE(TPM2_EXTERNAL)=0x2102,
	TYPE(TPM2_IN_CAP)=0x2103,
	TYPE(TPM2_IN_KEY)=0x2104,
	TYPE(TPM2_NV)=0x2105,
	TYPE(TPM2_PCR)=0x2106,
	TYPE(TPM2_AUTH)=0x2107,
	TYPE(TPM2_KEY)=0x2108,
	TYPE(TPM2_IDENTITY)=0x2109,
	TYPE(TPM2_SEAL)=0x210A
};

enum subtype_tpm2_external{
	SUBTYPE(TPM2_EXTERNAL,INPUT_COMMAND)=0x01,
	SUBTYPE(TPM2_EXTERNAL,RETURN_DATA)=0x02
};

enum subtype_tpm2_pcr_struct{
	SUBTYPE(TPM2_PCR,TPMS_PCR_SELECTION)=0x01,
	SUBTYPE(TPM2_PCR,TPML_PCR_SELECTION),
	SUBTYPE(TPM2_PCR,TPM2B_DIGEST),
	SUBTYPE(TPM2_PCR,TPML_DIGEST)
};

typedef struct tpm2_external_input_command{
	UINT16 tag;
	int    commandSize;
	int    commandCode;
}__attribute__((packed)) RECORD(TPM2_EXTERNAL,INPUT_COMMAND);

typedef struct tpm2_external_return_data{
	UINT16 tag;
	int    responseSize;
	int    responseCode;
}__attribute__((packed)) RECORD(TPM2_EXTERNAL,RETURN_DATA);

typedef struct tpms_pcr_selection{
	UINT16 hash;
	BYTE   sizeOfSelect;
	BYTE   * pcrSelect;
}__attribute__((packed)) RECORD(TPM2_PCR,TPMS_PCR_SELECTION);
typedef RECORD(TPM2_PCR,TPMS_PCR_SELECTION) TPMS_PCR_SELECTION;

typedef struct tpml_pcr_selection{
	int    count;
	TPMS_PCR_SELECTION * pcrSelections;
}__attribute__((packed)) RECORD(TPM2_PCR,TPML_PCR_SELECTION);
typedef RECORD(TPM2_PCR,TPML_PCR_SELECTION) TPML_PCR_SELECTION;

typedef struct tpm2b_digest{
	UINT16 size;
	BYTE   * buffer;
}__attribute__((packed)) RECORD(TPM2_PCR,TPM2B_DIGEST);
typedef RECORD(TPM2_PCR,TPM2B_DIGEST) TPM2B_DIGEST;

typedef struct tpml_digest{
	int    count;
	TPM2B_DIGEST * digests;
}__attribute__((packed)) RECORD(TPM2_PCR,TPML_DIGEST);
typedef RECORD(TPM2_PCR,TPML_DIGEST) TPML_DIGEST;

#endif
